﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using Module_Debug.AdbHelp;
using Module_Debug.Others.control_tools_lir.control_lir_com;


namespace Module_Debug.Others.control_tools_lir
{
    public partial class frm_tools_lir : Form
    {
        public string str_hs_config_path;
        public string str_ry_config_path;
        public string str_ry_config_name;
        public string str_ry_ratio_base;

        public string str_ry_target_lum;
        public string str_ry_delta;

        public string str_ry_gamma_node_cnt;

        public string str_ry_gamma_node_0;
        public string str_ry_gamma_rstring_r_0;
        public string str_ry_gamma_rstring_g_0;
        public string str_ry_gamma_rstring_b_0;

        public string str_ry_gamma_node_1;
        public string str_ry_gamma_rstring_r_1;
        public string str_ry_gamma_rstring_g_1;
        public string str_ry_gamma_rstring_b_1;

        public string str_ry_top_compensate_ratio;
        public string str_ry_bottom_compensate_ratio;
        public string str_ry_uniformity1;
        public string str_ry_uniformity2;

        public string str_ry_scale_avg_lum;
        public string str_ry_long_package;
        public string str_ry_special_param;

        OutParam out_param = new OutParam();
        InParam in_param = new InParam();
        OutResult result = new OutResult();
        TextBox[] txt_control = new TextBox[15];

        public string str_nova_file;
        private string str_current_path;
        private TextBox[] m_list = new TextBox[15];

        public frm_tools_lir()
        {
            InitializeComponent();
            val_file_exist();
        }

        private void frm_tools_lir_Load(object sender, EventArgs e)
        {
            init_form_data();
            init_nova_param();
        }
        private void init_nova_param()
        {
            this.txt_jt_lv.Text = "0.95";
            this.txt_ct_lv.Text = "0.9";
            m_list[0] = txt_data_1;
            m_list[1] = txt_data_2;
            m_list[2] = txt_data_3;
            m_list[3] = txt_data_4;
            m_list[4] = txt_data_5;

            m_list[5] = txt_data_6;
            m_list[6] = txt_data_7;
            m_list[7] = txt_data_8;
            m_list[8] = txt_data_9;
            m_list[9] = txt_data_10;

            m_list[10] = txt_data_11;
            m_list[11] = txt_data_12;
            m_list[12] = txt_data_13;
            m_list[13] = txt_data_14;
            m_list[14] = txt_data_15;

            str_current_path = System.Environment.CurrentDirectory;
            str_nova_file = str_current_path + "\\x_Novatek" + "\\Lir_function_config";
            if (!Directory.Exists(str_nova_file))
            {
                try
                {
                    Directory.CreateDirectory(str_nova_file);
                }
                catch (Exception e)
                {
                    MessageBox.Show("创建文件失败或异常！！");
                }
            }
            this.txt_output_dir.Text = str_nova_file;
            this.txt_output_dir.ReadOnly = true;
            this.txt_current_lir.Text = "0";
            this.btn_staus.BackColor = Color.Red;
        }
        private void init_form_data()
        {
            this.cbx_select_mode.Items.Add("LIR_RY");
            this.cbx_select_mode.Items.Add("LIR_HS");
            this.cbx_select_mode.Items.Add("LIR_NOVA");
            this.cbx_select_mode.SelectedIndex = 0;
            this.cbx_select_data.Items.Add("加载相机数据");
            this.cbx_select_data.Items.Add("加载测试仪数据");
            this.cbx_select_data.SelectedIndex = 0;
            this.cbx_special_set.Checked = false;

            txt_control[0] = txt_lum_1;
            txt_control[1] = txt_lum_2;
            txt_control[2] = txt_lum_3;
            txt_control[3] = txt_lum_4;
            txt_control[4] = txt_lum_5;

            txt_control[5] = txt_lum_6;
            txt_control[6] = txt_lum_7;
            txt_control[7] = txt_lum_8;
            txt_control[8] = txt_lum_9;
            txt_control[9] = txt_lum_10;

            txt_control[10] = txt_lum_11;
            txt_control[11] = txt_lum_12;
            txt_control[12] = txt_lum_13;
            txt_control[13] = txt_lum_14;
            txt_control[14] = txt_lum_15;

            in_param.gamma_node = new int[64];
            in_param.rstring_r = new int[64];
            in_param.rstring_g = new int[64];
            in_param.rstring_b = new int[64];

        }
        private void load_file_init(string str_file)
        {
            string str_file_ini = str_file + "\\visionox_config.ini";
            if (!File.Exists(str_file_ini))
            {
                //MessageBox.Show("Ini文件丢失！");
                FileStream file = new FileStream(str_file_ini, FileMode.CreateNew);
                file.Close();
                com_sys_function.ini_file_write("PROJECT", "project_name", "RX692CX", str_file_ini);

                com_sys_function.ini_file_write("PROJECT_SPECIAL_PARAM", "str_ry_scale_avg_lum", "true", str_file_ini);
                com_sys_function.ini_file_write("PROJECT_SPECIAL_PARAM", "str_ry_long_package", "true", str_file_ini);
                com_sys_function.ini_file_write("PROJECT_SPECIAL_PARAM", "str_ry_special_param", "true", str_file_ini);

                com_sys_function.ini_file_write("PROJECT_CONFIG_PRAM", "str_ry_target_lum", "500", str_file_ini);
                com_sys_function.ini_file_write("PROJECT_CONFIG_PRAM", "str_ry_delta", "144", str_file_ini);

                com_sys_function.ini_file_write("PROJECT_CONFIG_PRAM", "str_ry_ratio_base", "180", str_file_ini);
                com_sys_function.ini_file_write("PROJECT_CONFIG_PRAM", "str_ry_gamma_node_cnt_0", "2", str_file_ini);

                com_sys_function.ini_file_write("PROJECT_CONFIG_PRAM", "str_ry_gamma_node_0", "255", str_file_ini);
                com_sys_function.ini_file_write("PROJECT_CONFIG_PRAM", "str_ry_gamma_rstring_r_0", "2864", str_file_ini);
                com_sys_function.ini_file_write("PROJECT_CONFIG_PRAM", "str_ry_gamma_rstring_g_0", "2449", str_file_ini);
                com_sys_function.ini_file_write("PROJECT_CONFIG_PRAM", "str_ry_gamma_rstring_b_0", "3174", str_file_ini);

                com_sys_function.ini_file_write("PROJECT_CONFIG_PRAM", "str_ry_gamma_node_1", "239", str_file_ini);
                com_sys_function.ini_file_write("PROJECT_CONFIG_PRAM", "str_ry_gamma_rstring_r_1", "2792", str_file_ini);
                com_sys_function.ini_file_write("PROJECT_CONFIG_PRAM", "str_ry_gamma_rstring_g_1", "2395", str_file_ini);
                com_sys_function.ini_file_write("PROJECT_CONFIG_PRAM", "str_ry_gamma_rstring_b_1", "3095", str_file_ini);

                com_sys_function.ini_file_write("PROJECT_CONFIG_PRAM", "str_ry_top_compensate_ratio", "100", str_file_ini);
                com_sys_function.ini_file_write("PROJECT_CONFIG_PRAM", "str_ry_bottom_compensate_ratio", "100", str_file_ini);
                com_sys_function.ini_file_write("PROJECT_CONFIG_PRAM", "str_ry_uniformity1", "100", str_file_ini);
                com_sys_function.ini_file_write("PROJECT_CONFIG_PRAM", "str_ry_uniformity2", "95", str_file_ini);
            }

            str_ry_config_name = com_sys_function.ini_file_read("PROJECT","project_name", str_file_ini);

            str_ry_scale_avg_lum = com_sys_function.ini_file_read("PROJECT_SPECIAL_PARAM", "str_ry_scale_avg_lum", str_file_ini);
            str_ry_long_package = com_sys_function.ini_file_read("PROJECT_SPECIAL_PARAM", "str_ry_long_package", str_file_ini);
            str_ry_special_param = com_sys_function.ini_file_read("PROJECT_SPECIAL_PARAM", "str_ry_special_param", str_file_ini);


            str_ry_target_lum = com_sys_function.ini_file_read("PROJECT_CONFIG_PRAM", "str_ry_target_lum", str_file_ini);
            str_ry_delta = com_sys_function.ini_file_read("PROJECT_CONFIG_PRAM", "str_ry_delta", str_file_ini);

            str_ry_ratio_base = com_sys_function.ini_file_read("PROJECT_CONFIG_PRAM", "str_ry_ratio_base", str_file_ini);
            str_ry_gamma_node_cnt = com_sys_function.ini_file_read("PROJECT_CONFIG_PRAM", "str_ry_gamma_node_cnt_0", str_file_ini);

            str_ry_gamma_node_0 = com_sys_function.ini_file_read("PROJECT_CONFIG_PRAM", "str_ry_gamma_node_0", str_file_ini);
            str_ry_gamma_rstring_r_0 = com_sys_function.ini_file_read("PROJECT_CONFIG_PRAM", "str_ry_gamma_rstring_r_0", str_file_ini);
            str_ry_gamma_rstring_g_0 = com_sys_function.ini_file_read("PROJECT_CONFIG_PRAM", "str_ry_gamma_rstring_g_0", str_file_ini);
            str_ry_gamma_rstring_b_0 = com_sys_function.ini_file_read("PROJECT_CONFIG_PRAM", "str_ry_gamma_rstring_b_0", str_file_ini);

            str_ry_gamma_node_1 = com_sys_function.ini_file_read("PROJECT_CONFIG_PRAM", "str_ry_gamma_node_1", str_file_ini);
            str_ry_gamma_rstring_r_1 = com_sys_function.ini_file_read("PROJECT_CONFIG_PRAM", "str_ry_gamma_rstring_r_1", str_file_ini);
            str_ry_gamma_rstring_g_1 = com_sys_function.ini_file_read("PROJECT_CONFIG_PRAM", "str_ry_gamma_rstring_g_1", str_file_ini);
            str_ry_gamma_rstring_b_1 = com_sys_function.ini_file_read("PROJECT_CONFIG_PRAM", "str_ry_gamma_rstring_b_1", str_file_ini);

            str_ry_top_compensate_ratio = com_sys_function.ini_file_read("PROJECT_CONFIG_PRAM", "str_ry_top_compensate_ratio", str_file_ini);
            str_ry_bottom_compensate_ratio = com_sys_function.ini_file_read("PROJECT_CONFIG_PRAM", "str_ry_bottom_compensate_ratio", str_file_ini);
            str_ry_uniformity1 = com_sys_function.ini_file_read("PROJECT_CONFIG_PRAM", "str_ry_uniformity1", str_file_ini);
            str_ry_uniformity2 = com_sys_function.ini_file_read("PROJECT_CONFIG_PRAM", "str_ry_uniformity2", str_file_ini);

        }
        public void val_file_exist()
        {
            string str_current_path = System.Environment.CurrentDirectory;
            string str_path = str_current_path + "\\x_Raydium" + "\\Lir_function_config";
            str_ry_config_path = str_path;
            if (!Directory.Exists(str_path))
            {
                try
                {
                    Directory.CreateDirectory(str_ry_config_path);
                }
                catch (Exception e)
                {
                    MessageBox.Show("创建文件失败或异常！！");
                }
            }
            int nRet = com_function_lir.api_lir_init(str_ry_config_path);
            if (nRet != 0)
            {
                MessageBox.Show("初始化库文件失败！！" + " 错误码：" + nRet.ToString());
            }

            string str_hs_path = str_current_path + "\\x_Hisi3288" + "\\Lir_function_config";
            str_hs_config_path = str_hs_path;
            if (!Directory.Exists(str_hs_path))
            {
                try
                {
                    Directory.CreateDirectory(str_hs_path);
                }
                catch (Exception e)
                {
                    MessageBox.Show("创建文件失败或异常！！");
                }
            }
        }
        private void gbx_content_name_Enter(object sender, EventArgs e)
        {
        }

        private void cbx_select_mode_SelectedIndexChanged(object sender, EventArgs e)
        {
            //int iselect_index = cbx_select_mode.SelectedIndex;

            //if (this.cbx_select_mode.SelectedIndex == 0)
            //{
            //    tab_page_hs.Parent = null;
            //    tab_page_ry.Parent = tab_control_main;
            //    tab_page_result.Parent = tab_control_main;
            //}
            //else if (this.cbx_select_mode.SelectedIndex == 1)
            //{
                
            //    tab_page_hs.Parent = tab_control_main;
            //    tab_page_ry.Parent = null;
            //    tab_page_result.Parent = null;
            //}
        }

        private void ini_ry_work()
        {

        }
        private void produce_current_data()
        {

        }
        //一键设置
        private void btn_one_key_load_Click(object sender, EventArgs e)
        {
            
        }
        //获取亮度
        private void btn_get_lut_Click(object sender, EventArgs e)
        {

        }
        //加载参数
        private void btn_load_param_Click(object sender, EventArgs e)
        {
            load_file_init(str_ry_config_path);

            this.cbx_scale_select.Checked = Convert.ToBoolean(str_ry_scale_avg_lum);
            this.cbx_long_package.Checked = Convert.ToBoolean(str_ry_long_package);
            this.cbx_special_set.Checked = Convert.ToBoolean(str_ry_special_param);

            this.txt_project_name.Text = str_ry_config_name;
            this.txt_target_lum.Text = str_ry_target_lum;
            this.txt_delta.Text = str_ry_delta;

            this.txt_base.Text = str_ry_ratio_base;
            this.txt_cnt.Text = str_ry_gamma_node_cnt;

            this.txt_node_1.Text = str_ry_gamma_node_0;
            this.txt_rs_r0.Text = str_ry_gamma_rstring_r_0;
            this.txt_rs_g0.Text = str_ry_gamma_rstring_g_0;
            this.txt_rs_b0.Text = str_ry_gamma_rstring_b_0;

            this.txt_node_2.Text = str_ry_gamma_node_1;//
            this.txt_rs_r1.Text = str_ry_gamma_rstring_r_1;
            this.txt_rs_g1.Text = str_ry_gamma_rstring_g_1;//
            this.txt_rs_b1.Text = str_ry_gamma_rstring_b_1;

            this.txt_top_ratito.Text = str_ry_top_compensate_ratio;
            this.txt_bottom_ratito.Text = str_ry_bottom_compensate_ratio;
            this.txt_uniformity_1.Text = str_ry_uniformity1;
            this.txt_uniformity_2.Text = str_ry_uniformity2;

            in_param.str_id = str_ry_config_name;
            in_param.target_lum = float.Parse(str_ry_target_lum);
            in_param.delta = float.Parse(str_ry_delta);
            if(bool.Parse(str_ry_special_param))
            {
                in_param.check_type = 1;
            }
            else
            {
                in_param.check_type = 0;
            }
            if (bool.Parse(str_ry_long_package))
            {
                in_param.long_package = 1;
            }
            else
            {
                in_param.long_package = 0;
            }
            if (bool.Parse(str_ry_scale_avg_lum))
            {
                in_param.scale_lum = 1;
            }
            else
            {
                in_param.scale_lum = 0;
            }
            in_param.gamma_node_cnt = int.Parse(str_ry_gamma_node_cnt);
            in_param.ratio_base = int.Parse(str_ry_ratio_base);
            int[] p_value = { 0, 0, 0, 0, 0, 0, 0, 0 };
            in_param.rtn_value = p_value;


            in_param.gamma_node[0] = int.Parse(str_ry_gamma_node_0);
            in_param.rstring_r[0] = int.Parse(str_ry_gamma_rstring_r_0);
            in_param.rstring_g[0] = int.Parse(str_ry_gamma_rstring_g_0);
            in_param.rstring_b[0] = int.Parse(str_ry_gamma_rstring_b_0);

            in_param.gamma_node[1] = int.Parse(str_ry_gamma_node_1);
            in_param.rstring_r[1] = int.Parse(str_ry_gamma_rstring_r_1);
            in_param.rstring_g[1] = int.Parse(str_ry_gamma_rstring_g_1);
            in_param.rstring_b[1] = int.Parse(str_ry_gamma_rstring_b_1);

            in_param.top_compensate_ratio = int.Parse(str_ry_top_compensate_ratio); 
            in_param.bottom_compensate_ratio = int.Parse(str_ry_bottom_compensate_ratio); 
            in_param.uniformity1 = int.Parse(str_ry_uniformity1); 
            in_param.uniformity2 = int.Parse(str_ry_uniformity2); 

            int nRet = com_function_lir.api_set_param(in_param ,out out_param);

            int iLength = out_param.iLength;
            if(iLength==15)
            {
                for(int i=0;i<15;i++)
                {
                    txt_control[i].Text = out_param.data[i].ToString();
                }
            }
            if (iLength == 25)
            {
               
            }

        }
        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void btn_load_code_Click(object sender, EventArgs e)
        {

        }

        private void btn_output_code_click(object sender, EventArgs e)
        {

        }

        private void checkbox_set_CheckedChanged(object sender, EventArgs e)
        {

        }
        //运行代码
        private void button1_Click(object sender, EventArgs e)
        {
            txt_get_lum.Text = "";
            rch_txt_return_code.Text = "";
            rch_txt_in_code.Text = "";
            rch_txt_out_code.Text = "";

            com_function_lir.api_run_function(out result);
            txt_get_lum.Text = result.d_persent_lum.ToString();
            rch_txt_return_code.Text = System.Text.Encoding.ASCII.GetString(result.str_return_code);
            rch_txt_in_code.Text = System.Text.Encoding.ASCII.GetString(result.str_cmd_int);
            rch_txt_out_code.Text = System.Text.Encoding.ASCII.GetString(result.str_cmd_result);
            int over = 0;
        }

        private void button5_Click(object sender, EventArgs e)
        {
            this.tab_control_main.SelectedIndex = 0;
        }
        //保存
        private void btn_save_Click(object sender, EventArgs e)
        {
            string str_file_ini = str_ry_config_path + "\\visionox_config.ini";

            str_ry_config_name = txt_project_name.Text;

            str_ry_scale_avg_lum = cbx_scale_select.Checked.ToString();
            str_ry_long_package = cbx_long_package.Checked.ToString();
            str_ry_special_param = cbx_special_set.Checked.ToString();


            str_ry_target_lum = txt_target_lum.Text;
            str_ry_delta = txt_delta.Text;

            str_ry_ratio_base = txt_base.Text;
            str_ry_gamma_node_cnt = txt_cnt.Text;

            str_ry_gamma_node_0 = txt_node_1.Text;
            str_ry_gamma_rstring_r_0 = txt_rs_r0.Text;
            str_ry_gamma_rstring_g_0 = txt_rs_g0.Text;
            str_ry_gamma_rstring_b_0 = txt_rs_b0.Text;

            str_ry_gamma_node_1 = txt_node_2.Text;
            str_ry_gamma_rstring_r_1 = txt_rs_r1.Text;
            str_ry_gamma_rstring_g_1 = txt_rs_g1.Text;
            str_ry_gamma_rstring_b_1 = txt_rs_b1.Text;

            str_ry_top_compensate_ratio = txt_top_ratito.Text;
            str_ry_bottom_compensate_ratio = txt_bottom_ratito.Text;
            str_ry_uniformity1 = txt_uniformity_1.Text;
            str_ry_uniformity2 = txt_uniformity_2.Text;

            com_sys_function.ini_file_write("PROJECT", "project_name", str_ry_config_name, str_file_ini);
            com_sys_function.ini_file_write("PROJECT_SPECIAL_PARAM", "str_ry_scale_avg_lum",str_ry_scale_avg_lum,str_file_ini);
            com_sys_function.ini_file_write("PROJECT_SPECIAL_PARAM", "str_ry_long_package",str_ry_long_package,str_file_ini);
            com_sys_function.ini_file_write("PROJECT_SPECIAL_PARAM", "str_ry_special_param",str_ry_special_param,str_file_ini);

            com_sys_function.ini_file_write("PROJECT_CONFIG_PRAM", "str_ry_target_lum", str_ry_target_lum,str_file_ini);
            com_sys_function.ini_file_write("PROJECT_CONFIG_PRAM", "str_ry_delta",str_ry_delta,str_file_ini);

            com_sys_function.ini_file_write("PROJECT_CONFIG_PRAM", "str_ry_ratio_base", str_ry_ratio_base,str_file_ini);
            com_sys_function.ini_file_write("PROJECT_CONFIG_PRAM", "str_ry_gamma_node_cnt_0", str_ry_gamma_node_cnt, str_file_ini);

            com_sys_function.ini_file_write("PROJECT_CONFIG_PRAM", "str_ry_gamma_node_0", str_ry_gamma_node_0, str_file_ini);
            com_sys_function.ini_file_write("PROJECT_CONFIG_PRAM", "str_ry_gamma_rstring_r_0", str_ry_gamma_rstring_r_0, str_file_ini);
            com_sys_function.ini_file_write("PROJECT_CONFIG_PRAM", "str_ry_gamma_rstring_g_0", str_ry_gamma_rstring_g_0, str_file_ini);
            com_sys_function.ini_file_write("PROJECT_CONFIG_PRAM", "str_ry_gamma_rstring_b_0", str_ry_gamma_rstring_b_0, str_file_ini);

            com_sys_function.ini_file_write("PROJECT_CONFIG_PRAM", "str_ry_gamma_node_1", str_ry_gamma_node_1, str_file_ini);
            com_sys_function.ini_file_write("PROJECT_CONFIG_PRAM", "str_ry_gamma_rstring_r_1", str_ry_gamma_rstring_r_1, str_file_ini);
            com_sys_function.ini_file_write("PROJECT_CONFIG_PRAM", "str_ry_gamma_rstring_g_1", str_ry_gamma_rstring_g_1, str_file_ini);
            com_sys_function.ini_file_write("PROJECT_CONFIG_PRAM", "str_ry_gamma_rstring_b_1", str_ry_gamma_rstring_b_1, str_file_ini);

            com_sys_function.ini_file_write("PROJECT_CONFIG_PRAM", "str_ry_top_compensate_ratio", str_ry_top_compensate_ratio, str_file_ini);
            com_sys_function.ini_file_write("PROJECT_CONFIG_PRAM", "str_ry_bottom_compensate_ratio", str_ry_bottom_compensate_ratio, str_file_ini);
            com_sys_function.ini_file_write("PROJECT_CONFIG_PRAM", "str_ry_uniformity1", str_ry_uniformity1, str_file_ini);
            com_sys_function.ini_file_write("PROJECT_CONFIG_PRAM", "str_ry_uniformity2", str_ry_uniformity2, str_file_ini);
            
            MessageBox.Show("保存参数成功！！！");
        }

        private void frm_tools_lir_FormClosed(object sender, FormClosedEventArgs e)
        {
            com_function_lir.api_lir_release();
            com_fun_hs.api_lir_hs_release();
        }
        string strText = "";
        string[] str_sp = new string[3];
        private void btn_hs_run_Click(object sender, EventArgs e)
        {
            string str_file_path= str_hs_config_path + "\\sirc_reg.txt";
            int isucceesss = com_fun_hs.api_lir_hs_run();
            if (isucceesss == 0)
            {
                StreamReader sR = File.OpenText(str_file_path);
                string nextLine;
                while ((nextLine = sR.ReadLine()) != null)
                {
                    strText = strText + nextLine + "\r\n";
                    if (sR.EndOfStream)
                    {
                        strText = strText + nextLine;
                    }
                }
                sR.Close();
                this.richTextBox2.Text = strText;
                int ver = 0;
            }

            string str_current_path = System.Environment.CurrentDirectory;
            string str_sirc_path = str_current_path + "//SIRC.txt";
            StreamReader sRR = File.OpenText(str_sirc_path);
            string str_next_line;
            while ((str_next_line = sRR.ReadLine()) != null)
            {
                str_sp = str_next_line.Split(',');
            }
            sRR.Close();

            txt_target_per.Text = str_sp[1].ToString();
            txt_current_per.Text = str_sp[2].ToString();

        }

        private void btn_send_Click(object sender, EventArgs e)
        {
            string str= strText;
            com_sys_param parm = new com_sys_param();
            parm.iselect_win = Setting.IC_Type.HI3288_V110_C21;
            parm.iselect_page = 2;
            parm.str_cmd = str;
            parm.icheck = true;
            frmMain.frmain.Open_Gamma_tool_Click(parm, e);
        }

        private void btn_hs_save_Click(object sender, EventArgs e)
        {

        }
       
        private void btn_hs_load_Click(object sender, EventArgs e)
        {
           
        }

        private void btn_load_data_Click(object sender, EventArgs e)
        {

        }

        private void btn_save_data_Click(object sender, EventArgs e)
        {

        }
        bool b_init = true;
        double d_uniformity = 0.0;
        int index = 0;
        string str_init_code="";
        string str_run_code = "";
        private void btn_run_function(object sender, EventArgs e)
        {
            if(b_init)
            {
                index++;
                com_fun_nova.run_nova_lir(index,str_nova_file, out str_init_code, out d_uniformity);
                this.rchtxt_init_code.Text = str_init_code;
                b_init = false;
            }
            else
            {
               
                OpenFileDialog dialog = new OpenFileDialog();
                dialog.Multiselect = false;//该值确定是否可以选择多个文件
                dialog.Title = "请选择文件夹";
                dialog.Filter = "数据文件(*.csv,*.CSV)|*.csv;*.CSV;";
                string file = "";
                if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    index++;
                    file = dialog.FileName;
                }
                else
                {
                    return;
                }

                double[] d_array_lv = com_fun_nova.CalculateCSVUniformity(0 ,file, ref d_uniformity);
                this.txt_current_lir.Text = d_uniformity.ToString();
                updata_data_control(d_array_lv);

                string str_dst_mu = str_nova_file + "\\" + "output_uniformity" + "\\";
                string str_dst_file = str_dst_mu + "VDCUniformity_" + (index - 1).ToString() + ".csv";

                FileInfo file_info = new FileInfo(file);
                if(file_info.Exists)
                {
                    file_info.CopyTo(str_dst_file,true);
                }

                com_fun_nova.run_nova_lir(index, str_nova_file, out str_run_code, out d_uniformity);
                tab_nova_command.SelectedIndex = 1;
                this.rchtxt_nova_output.BackColor = Color.YellowGreen;
                this.rchtxt_nova_output.Text = str_run_code;

                double dTarget = Convert.ToDouble(this.txt_jt_lv.Text);
                double dLow = Convert.ToDouble(this.txt_ct_lv.Text);
                if (d_uniformity >= dTarget)
                {
                    this.btn_staus.BackColor = Color.Green;
                    this.btn_staus.Text = "OK";
                }
                else if(d_uniformity < dLow)
                {
                    this.btn_staus.BackColor = Color.Red;
                    this.btn_staus.Text = "NG";
                }
            }
        }
        private void updata_data_control(double[] array)
        {
            if(array.Length == 9)
            {
                for(int i=0;i<9;i++)
                {
                    m_list[i].Text = array[i].ToString();
                }
            }
            else if(array.Length == 15)
            {

            }
        }
        private void button6_Click(object sender, EventArgs e)
        {

        }

        private void btn_change_cmd_win_Click(object sender, EventArgs e)
        {

            if(tab_nova_command.SelectedIndex == 0)
            {
                frmMain.frmain.common_gamma_function(str_init_code);
            }
            else if(tab_nova_command.SelectedIndex == 1)
            {
                frmMain.frmain.common_gamma_function(str_run_code);
            }
            else
            {
                string str_cmd = "";
                frmMain.frmain.common_gamma_function(str_cmd);
            }
            
        }

        private void btn_nova_reset_Click(object sender, EventArgs e)
        {
            index = 0;
            this.txt_current_lir.Text = "0";
            this.rchtxt_init_code.Clear();
            this.rchtxt_nova_output.Clear();
            b_init = true;
            this.rchtxt_nova_output.BackColor = Color.White;
        }
    }
}
